Skip to content

Conversation

@artemcm
Copy link
Contributor

@artemcm artemcm commented Dec 16, 2025

This change adds collection of three metrics to the scanner:

  • number of Swift module lookups
  • number of named Clang module lookups
  • recorded number of Clang modules which were imported into a Swift module by name

It re-uses the prior '-Rdependency-scan-cache', renaming it to '-Rdependency-scan' and adds emission of the above metrics as remarks when this flag is enabled. Followup changes will add further remarks about dependency scanner progress.

@artemcm
Copy link
Contributor Author

artemcm commented Dec 16, 2025

@swift-ci test


// CHECK-REMARK-SAVE: remark: Number of Swift module queries: '21'
// CHECK-REMARK-SAVE: remark: Number of named Clang module queries: '6'
// CHECK-REMARK-SAVE: remark: Number of recorded Clang module dependencies queried by-name from a Swift client: '6'
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although it may be prudent to, one day, make the compiler assert/error if the number of queries exceeds the number of recorded by-name Clang dependencies, we are not quite there yet. I have a couple of follow-up changes in the pipeline which should remove further sources of duplicate queries.

@cachemeifyoucan
Copy link
Contributor

I guess you forgot to add the Options.td change.

I assume I suggested remarks. The other option is to using StatsReporter that writes with -stats-output-dir for example. I don't really mind which one is used.

@artemcm artemcm force-pushed the DependencyScanningMetrics branch from 7fed579 to 1349167 Compare December 16, 2025 17:16
@artemcm
Copy link
Contributor Author

artemcm commented Dec 16, 2025

I assume I suggested remarks. The other option is to using StatsReporter that writes with -stats-output-dir for example. I don't really mind which one is used.

I think remarks fit okay. I have long wanted the scanner to emit more-detailed overall remarks about the work it is doing and putting in all the plumbing this PR adds will make that easier to build on.

@artemcm
Copy link
Contributor Author

artemcm commented Dec 16, 2025

@swift-ci test

std::shared_ptr<llvm::cas::ActionCache> ActionCache;

// Metrics about actions performed by the scanner
std::shared_ptr<ScannerMetrics> scanMetrics;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see why this needs to be shared_ptr and same for all other ScannerMetrics references. CAS is shared_ptr mainly because of the APIs from llvm/clang need that. And here it can always just be a reference to ScannerMetrics in ModuleDependencyScanner, or maybe even move to DependencyScannerDiagnosticReporter (where it can decide if it needs to increment the counter and report the metrics based on the flag).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's fine, I moved the metrics into DependencyScannerDiagnosticReporter and added methods to it which will increment the appropriate counter if remark emission is enabled.

@artemcm artemcm force-pushed the DependencyScanningMetrics branch 2 times, most recently from 5e76a2f to bff1749 Compare December 16, 2025 18:27
@artemcm
Copy link
Contributor Author

artemcm commented Dec 16, 2025

@swift-ci test

@artemcm artemcm force-pushed the DependencyScanningMetrics branch from bff1749 to eca8925 Compare December 16, 2025 20:30
@artemcm
Copy link
Contributor Author

artemcm commented Dec 16, 2025

@swift-ci smoke test

@artemcm artemcm enabled auto-merge December 16, 2025 20:47
@artemcm artemcm force-pushed the DependencyScanningMetrics branch from eca8925 to e6761b1 Compare December 17, 2025 17:32
@artemcm
Copy link
Contributor Author

artemcm commented Dec 17, 2025

@swift-ci smoke test

@artemcm
Copy link
Contributor Author

artemcm commented Dec 17, 2025

@swift-ci smoke test Linux platform

…s and emit them as remarks

This change adds collection of three metrics to the scanner:
- number of Swift module lookups
- number of named Clang module lookups
- recorded number of Clang modules which were imported into a Swift module by name

It introduces '-Rdependency-scan', which acts as a super-set flag to the existing '-Rdependency-scan-cache' and adds emission of the above metrics as remarks when this flag is enabled. Followup changes will add further remarks about dependency scanner progress.
@artemcm artemcm force-pushed the DependencyScanningMetrics branch from e6761b1 to 7017034 Compare December 17, 2025 20:50
@artemcm
Copy link
Contributor Author

artemcm commented Dec 17, 2025

@swift-ci smoke test

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants